package com.campus.web.controller.management;


import com.campus.app.service.CheckMorningExercisesService;
import com.campus.commons.entity.CheckMorningExercise;
import com.campus.commons.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 晨练检查表 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/checkMorning")
public class CheckMorningExerciseController {
    @Autowired
    CheckMorningExercisesService checkMorningExercisesService;

    /**
     * 查询所有分页
     *
     * @return
     */
    @RequestMapping("/all")
    public Result<List<CheckMorningExercise>> getAll(int page, int limit) {
        Result<List<CheckMorningExercise>> checkHealth = checkMorningExercisesService.getCheckHealth(page, limit);

        return checkHealth;
    }

    /**
     * 复合查询
     *
     * @param start
     * @param end
     * @param page
     * @param limit
     * @param className
     * @param isRed
     * @return
     */
    @PostMapping("/allDate")
    public Result<List<CheckMorningExercise>> getAllByDate(@RequestParam(required = true) String start, @RequestParam(required = true) String end, int page, int limit, @RequestParam(required = true) String className, int isRed) {
        Result<List<CheckMorningExercise>> checkHealthByDate = checkMorningExercisesService.getCheckMorningByDate(start, end, page, limit, className,isRed);
        return checkHealthByDate;
    }

    /**
     * 删除一条查班记录
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    Result Delete(Integer id) {

        return checkMorningExercisesService.del(id);
    }

    /**
     * 修改方法
     *
     * @param checkMorningExercise
     * @return
     */
    @PostMapping("/update")
    Result Update(CheckMorningExercise checkMorningExercise) {
        return checkMorningExercisesService.upDate(checkMorningExercise);
    }

    @PostMapping("/isRed")
    Result<List<CheckMorningExercise>> listResult(int page,int limit) {
        return checkMorningExercisesService.getIsRed(page, limit);
    }

    //<editor-fold desc="操作缓存">
    @ApiOperation("添加查晨练缓存信息")
    @PostMapping("/addCache")
    public Result addCacheMap(CheckMorningExercise checkMorningExercise) {
        return checkMorningExercisesService.addCheckMorningExercise(checkMorningExercise);
    }
    @ApiOperation("删除查晨练缓存")
    @PostMapping("/delCache")
    public Result deleteCacheMap(Integer classId) {
        return checkMorningExercisesService.delCheckMorningExercise(classId);
    }
    @ApiOperation("更新查晨练缓存")
    @PostMapping("/upCache")
    public Result updateCacheMap(CheckMorningExercise checkMorningExercise) {
        return checkMorningExercisesService.upCheckMorningExercise(checkMorningExercise);

    }
    @ApiOperation("获取查晨练缓存")
    @PostMapping("/getCache")
    public Result getCacheMap() {
        return checkMorningExercisesService.getCacheCheckMorning();
    }
    //</editor-fold>
}
